/** 
 * LogoutAction.java
 * 
 * 1.0
 * 
 * 04/07/2014
 * 
 * Copyright (c) 2013 FPT Software.
 * FPT Building, Street No1, DaNang Industrial Zone, AnDon, 
 * AnHaiBac Ward, SonTra District, DaNang City.
 * All rights reserved.
 */
package com.jms.fu.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * Class to implement the action Logout
 * 
 * @author Design Framework Group
 */
public class LogoutAction extends Action{
	private static Logger logger = Logger.getLogger(LogoutAction.class);
	
	/**
	 * Method execute, called when executing the action
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		try {
			HttpSession session = request.getSession();
			String user = (String)session.getAttribute("user");
			session.invalidate();
			logger.info("Account logged out: " + user);
			return mapping.findForward("login");
		} catch (Exception e) {
			logger.error(e.getMessage());
			return mapping.findForward("login");
		}
	}	
}
